<template>
  <div class="header">
    <img class="item-logo" src="@/assets/logo.png">
    <div class="navList">
      <div class="home" :class='active==index ? "active" : "" ' v-for="(temp,index) in array" :key="index" @click=" routerLink(temp.href)">{{temp.name}}</div>
    </div>
    <div class="search">
      <input v-model="kw" placeholder="输入关键词搜索相关内容">
      <i class="item-search-btn el-icon-search" @click="searchHandler"></i>
    </div>
  </div>
</template>

<script>
// api
import { searchLiek } from "@/api/miva";
export default {
  computed: {
    active() {
      return this.$store.state.header_active;
    },
    // searchData() {
    //   return this.$store.state.searchData;
    // }
  },
  data() {
    return {
      // array:["首页","案例","专题","合作","关于" ]
      array: [
        {
          name: "首页",
          href: "home"
        },
        {
          name: "案例",
          href: "allCase"
        },
        {
          name: "专题",
          href: "subject"
        },
        {
          name: "合作",
          href: "cooperation"
        },
        {
          name: "关于",
          href: "about"
        }
      ],
      kw: ''
    };
  },
  methods: {
    async searchHandler() {
      const res = await searchLiek({kw: this.kw})
      console.log(res)
      this.$store.commit('SAVE_SEARCHDATA', res.data)
      this.routerLink("search");
    },
    routerLink(name) {
      this.$router.push({
        name
      });
    }
  }
};
</script>

<style lang="less">
.header {
  width: 1200px;
  margin: auto;
  height: 60px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
  user-select: none;
  .nav {
    overflow: hidden;
    width: 175px;
    padding: 0 10px;
    box-sizing: border-box;
    img {
      width: 100%;
    }
  }
  .navList {
    width: 700px;
    display: flex;
    align-items: flex-start;
    color: #606060;
    font-size: 16px;
    font-weight:bold;
    .home {
      height: 60px;
      line-height: 60px;
      padding: 0px 30px;
      margin: 0 10px;
      border-top: 3px solid transparent;
    }
  }
  .search {
    height: 30px;
    position: relative;
    margin-right: 30px;
  }
  .item-search-btn {
    position: absolute;
    top: 50%;
    right: 10px;
    transform: translateY(-50%);
    color: #888;
  }
  .search input {
    outline: 0;
    border: none;
    height: 30px;
    line-height: 30px;
    border-radius: 16px;
    background: #f4f4f4;
    padding: 0 25px;
    text-align: center;
    font-size: 12px;
  }
  .active {
    border-color: #e44f50 !important;
    box-shadow: 0px 2px 16px 0px rgba(189, 189, 189, 0.22);
  }
}
</style>